var configPro = {};
configPro.server = "https://sdqn5b.cn:449/";
configPro.serverApp = "https://sdqn5b.cn:448/"
configPro.logger = "debugger";

function checkJson(e) {
	for (key in e) {
		if (e[key] == null || e[key] == 'undefind' || e[key] == '') {
			return false;
		}
	}
	return true;
}

function acquire() {
	this.parameter;
	this.parameterMap = {};
	this.test = function() {
		if (window.location.href.split("?") <= 0) {
			return null;
		} else {
			this.parameter = window.location.href.split("?")[1];
		}
	}
	this.packaging = function() {
		if (!this.parameter) {
			return false;
		}
		for (var i = 0; i < this.parameter.split("&").length; i++) {
			var name = this.parameter.split("&")[i].split("=")[0];
			var val = this.parameter.split("&")[i].split("=")[1];
			this.parameterMap[name] = val;
		}
	}
	this.test();
	this.packaging();
}

function jsonToString(pathMap) {
	var path = "";
	for (var key in pathMap) {
		if (path.length != 0) {
			path = path + "&" + key + "=" + pathMap[key];
		} else {
			path = key + "=" + pathMap[key];
		}
	}
	if (typeof(path) == 'undefined') {
		return "code=" + getCode(8);
	} else {
		return path;
	}
}

function getToken() {

}
function sendPost(urls, pathMap, queryMap, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		data: JSON.stringify(queryMap),
		method: "POST",
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("data:" + JSON.stringify(queryMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}

function sendGet(urls, pathMap, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		method: "GET",
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}
function playGet(urls, pathMap, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		method: "GET",
		header: {
			'token': getToken()
		},
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}

function playPost(urls, pathMap, queryMap, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		data: JSON.stringify(queryMap),
		method: "POST",
		header: {
			'token': getToken()
		},
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("data:" + JSON.stringify(queryMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}

function playDelete(urls, pathMap, queryMap, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		data: JSON.stringify(queryMap),
		method: "DELETE",
		header: {
			'token': getToken()
		},
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("data:" + JSON.stringify(queryMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}

function playPut(urls, pathMap, queryMap, token, fn) {
	uni.request({
		url: configPro.server + urls + "?" + jsonToString(pathMap),
		data: JSON.stringify(queryMap),
		method: "PUT",
		header: {
			'token': getToken()
		},
		success: (res) => {
			if (configPro.logger == 'debugger') {
			    console.log("=============GET==============");
			    console.log("path:" + configPro.projectName + urls + "?" + jsonToString(pathMap));
			    console.log("data:" + JSON.stringify(queryMap));
			    console.log("bank:" + JSON.stringify(res));
			    console.log("=============END==============");
			}
			new fn(res);
		}
	});
}

export default{
	checkJson,acquire,getToken,playGet,playPost,playDelete,playPut,sendGet,sendPost
}
